import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    // name的作用：
    //  1. 当path比较长时，用name方便一些
    //  2. 在做路由跳转时，用{name: 'xxx', data:{}}
    //  this.$router.push({name: 'Login'})
    //  this.$router.push('/login')
    //  this.$router.push({path: '/login'})
    name: 'login',
    // 懒加载： 只有访问这个路由时，这个组件对应的代码才会加载进行
    // 如果不用懒加载，就会出现：一打开页面，所有的页面（组件）全部加载进来
    component: () => import(/* webpackChunkName: "login" */ '../views/login/login.vue')
  },
  {
    path: '/',
    name: 'layout',
    component: () => import(/* webpackChunkName: "layout" */ '../views/layout/layout.vue'),
    children: [
      {
        path: '', // 默认放置组件
        name: 'home',
        meta: { isKeepAlive: true },
        component: () => import(/* webpackChunkName: "home" */ '../views/home/home.vue')
      },
      {
        path: '/question',
        name: 'question',
        component: () => import(/* webpackChunkName: "question" */ '../views/question/question.vue')
      },
      {
        path: '/video',
        name: 'video',
        component: () => import(/* webpackChunkName: "video" */ '../views/video/video.vue')
      },
      {
        path: '/setting',
        name: 'setting',
        component: () => import(/* webpackChunkName: "setting" */ '../views/setting/setting.vue')
      }
    ]
  },
  {
    path: '/search',
    name: 'search',
    component: () => import(/* webpackChunkName: "search" */ '../views/search/search.vue')
  },
  {
    path: '/result',
    name: 'result',
    component: () => import(/* webpackChunkName: "result" */ '../views/search/result.vue')
  },
  {
    path: '/article/:id',
    name: 'article',
    component: () => import(/* webpackChunkName: "article" */ '../views/article/article.vue')
  },
  {
    path: '/user/profile',
    name: 'profile',
    component: () => import(/* webpackChunkName: "profile" */ '../views/setting/profile.vue')
  },
  {
    path: '/user/chat',
    name: 'chat',
    component: () => import(/* webpackChunkName: "chat" */ '../views/setting/chat.vue')
  }
]

const router = new VueRouter({
  routes
})

export default router
